/*
    Deferred Shader
*/

uniform sampler2D shading_ssao;
uniform sampler2D overbright;
uniform sampler2D rnm;

const float offset = 17.0;

varying vec2 coord;
varying vec2 uv;

// handy
const vec2 CL = vec2(1.0, 0.0);

vec4 blur(in sampler2D tex, in vec2 uv, in float blurSize) {
    vec4 sum = CL.yyyy;
    sum += texture2D(tex, vec2(blurSize * -5.0 + uv.x, uv.y)) * 0.03;
    sum += texture2D(tex, vec2(blurSize * -4.0 + uv.x, uv.y)) * 0.04;
    sum += texture2D(tex, vec2(blurSize * -3.0 + uv.x, uv.y)) * 0.08;
    sum += texture2D(tex, vec2(blurSize * -2.0 + uv.x, uv.y)) * 0.11;
    sum += texture2D(tex, vec2(blurSize * -1.0 + uv.x, uv.y)) * 0.15;
    sum += texture2D(tex, vec2(uv.x, uv.y)) * 0.16;
    sum += texture2D(tex, vec2(blurSize * 1.0 + uv.x, uv.y)) * 0.15;
    sum += texture2D(tex, vec2(blurSize * 2.0 + uv.x, uv.y)) * 0.11;
    sum += texture2D(tex, vec2(blurSize * 3.0 + uv.x, uv.y)) * 0.08;
    sum += texture2D(tex, vec2(blurSize * 4.0 + uv.x, uv.y)) * 0.04;
    sum += texture2D(tex, vec2(blurSize * 5.0 + uv.x, uv.y)) * 0.03;
    
    return sum;
}

void main() {
    
    gl_FragData[0] = blur(shading_ssao, uv, 0.003);
    gl_FragData[1] = blur(overbright, uv, 0.015);
}
